<?php
/**
 * Created by PhpStorm.
 * User: tandunzhao
 * Date: 2018/5/28
 * Time: 下午3:35
 */

namespace App\Modules\Order\Models;


use App\Modules\Home\Models\Address;
use App\Modules\Shop\Models\OrderProducts;
use Illuminate\Database\Eloquent\Model;

class Order extends Model
{
    protected $table = 'orders';
    protected $fillable = ['id','trade_no','uid','amount','transaction_id','payment_source','pay_end_at','pay_time','create_ip','status','addr_id','ship_fee','discount','discount_coupon _id','remark','is_batch_ship','notify_data','created_at','updated_at'];

    static function getOrder($task_id,$uid,$status)
    {
    	return self::where('task_id',$task_id)->where('uid',$uid)->where('status',$status)->first();
    }

    public function address() {
        return $this->belongsTo(Address::class,'addr_id');
    }

    public function order_products() {
        return $this->hasMany(OrderProducts::class,'order_id','id');
    }
}